<template>
<div class="mod-config">
  <el-dialog title="田块列表" :visible.sync="visible">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.name" placeholder="田块名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      ref="multipleTable"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        label="田块名称">
      </el-table-column>
      <el-table-column
        prop="farmlandAreaName"
        header-align="center"
        align="center"
        label="所属基地">
      </el-table-column>
      <el-table-column
        prop="cropDictName"
        header-align="center"
        align="center"
        label="农作物">
      </el-table-column>
      <el-table-column
        prop="handlerName"
        header-align="center"
        align="center"
        label="责任人">
      </el-table-column>
      <el-table-column
        prop="position"
        header-align="center"
        align="center"
        label="位置">
      </el-table-column>
      <el-table-column
        prop="farmlandStatusDesc"
        header-align="center"
        align="center"
        label="农田状态">
        <template slot-scope="scope">
            <el-tag v-if="scope.row.status === 0" size="small" type="warning">{{scope.row.farmlandStatusDesc}}</el-tag>
            <el-tag v-else-if="scope.row.status === 1" size="small" type="success">{{scope.row.farmlandStatusDesc}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="orderNum"
        header-align="center"
        align="center"
        width="80"
        label="排序编号">
      </el-table-column>
    </el-table>
    <!-- <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination> -->
  <span slot="footer" class="dialog-footer">
    <el-button @click="visible = false">关闭</el-button>
  </span>
  </el-dialog>
  
</div>
</template>

<script>
  export default {
    data () {
      return {
        dataForm: {
          name: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        bussFarmlandInfoIds:[],
        bussFarmlandInfoIdsName:[],
        deptid:'',
        visible:true
      }
    },
    components: {
    },
    activated () {
      // this.getDataList()
    },
    methods: {
      init(ids,deptid){
        this.visible =true
        this.bussFarmlandInfoIds = ids.split(",")
        this.deptid = deptid
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/buss/bussfarmlandinfo/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            // 'limit': this.pageSize,
            'limit': 99999,
            'jd': this.deptid,
            'name': this.dataForm.name,
            
            
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            var bussFarmlandInfoIds2 = this.bussFarmlandInfoIds

            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
           
            this.$nextTick(() => {
              if (bussFarmlandInfoIds2.length > 0) {
                bussFarmlandInfoIds2.forEach(x => {
                  data.page.list.forEach((y, index) => {
                      if (x == y.id) {
                        this.$refs.multipleTable.toggleRowSelection(data.page.list[index], true)
                      }
                  })
                })
              }
            })
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val

        this.bussFarmlandInfoIds = val.map(function(item){
            return item.id
        }).join(',')

        this.bussFarmlandInfoIdsname = val.map(function(item){
            return item.name
        }).join(',')

        this.$emit('bussFarmlandInfoSelectChange',this.bussFarmlandInfoIds,this.bussFarmlandInfoIdsname)

      },

    }
  }
</script>
